/* 
 * deal with structure
 */
#define offset(type, member) (size_t) (&((type *) 0) ->member)

#define container_of(ptr, type, member) ({ 
        const typeof( ((type *)0)->member ) *__mptr = (ptr); 
        (type *)( (char *)__mptr - offsetof(type,member) );}

/* get a single field in a im_if_gen_stats request */
#define IM_GET_GENSTAT_REQ_FIELD(im_if_gen_stats, field)  \
    (im_if_gen_stats->im_if_gen_req.field)

/*
 * debug control flags
 */
#undef PDEBUG
#ifdef LDD_DEBUG
#ifdef __KERNEL__
#define PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: [%s:%d] "
    fmt " ", __FUNCTION__, __LINE__, ## args)
#else
#define PDEBUG(fmt, args...) fprintf(stderr, "[%s:%d] "
    fmt " ", __FUNCTION__, __LINE__, ## args)
#endif
#else
#define PDEBUG(fmt, args...)
#endif

/*
 * copy from BSD source file include/assert.h
 */
#ifdef NDEBUG
#define	assert(e)	((void)0)
#define	_assert(e)	((void)0)
#else
#define	_assert(e)	assert(e)
#ifdef __STDC__
#define	assert(e)	((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
#else	/* PCC */
#define	assert(e)	((e) ? (void)0 : __assert(__FILE__, __LINE__, "e"))
#endif
#endif

    
#define ZC_PCL_DEBUG(s...) \
        if (zc_debug_pcl) { \
            printf(s); \
        }

#define QOS_TRACE( x ... ) printf( "\n" x );

#define HWIC_ASSERT(expr) { if (!(expr)) { printf ("ASSERTION FAILED: file \"%s\", line %d", __FILE__,__LINE__); exit(1); }}


/*
 * Handle 64bit big end and little end 
 */
#define LITTLE_END_MASK 0xffffffff                                        

#define GET_HC(big_end, little_end, hc)  (big_end) = (hc) >> 32; \  
                                         (little_end) = (hc) & LITTLE_END_MASK                                                   
#define SET_HC(big_end, little_end, hc)  (hc) = ((ulonglong)big_end) << 32; \                                                                  
                                         (hc) |= ((ulonglong)little_end)
#define LLU_TO_UINT64(p64, ull) GET_HC((p64)->big_end, (p64)->little_end, ull)                                                                     

void return_nothing(void *dummy, ...) { return; }

